package com.store.controller.hzl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.store.entity.Brand;
import com.store.service.hzl.BrandService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * ClassName:BrandController
 * package:com.store.controller.hzl
 * Description:
 *
 * @Date:2021/1/22 10:31
 * @Author: tank_黄志凌
 */
@Controller
@RequestMapping("/brand_hzl")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @RequestMapping("/addBrand")
    public String addBrand(HttpSession session, Brand brand){
        boolean result=brandService.addBrand(brand)>0;
        session.setAttribute("msg",result?"增加成功":"增加失败");
        return "redirect:/index_hzl/toBrand";
    }

    @RequestMapping("/toUpdateBrand")
    @ResponseBody
    public String toUpdateBrand(int id){
        Brand brand=brandService.queryBrandById(id);
        String string = JSON.toJSONString(brand);
        return string;
    }

    @RequestMapping("/updateBrand")
    public String updateBrand(Brand brand,HttpSession session){
        boolean result=brandService.updateBrand(brand)>0;
        session.setAttribute("msg",result?"保存成功":"保存失败");
        return "redirect:/index_hzl/toBrand";
    }

    @RequestMapping("/deleteBrand")
    public String deleteBrand(int id,HttpSession session){
        boolean result=brandService.deleteBrand(id)>0;
        session.setAttribute("msg",result?"删除成功":"删除失败");
        return "redirect:/index_hzl/toBrand";
    }

}
